﻿Imports Library

<Serializable()>
Public Class clsUIOption
#Region "property"

#Region "StockInfoLine option"

    Public Property IsScroll As Boolean 'if scroll the text
        Get
            Return m_IsScroll
        End Get
        Set(value As Boolean)
            m_IsScroll = value
        End Set
    End Property

    ''' <summary>
    ''' hide fields for display,element from 0 to field count,field 0 is preserved,
    ''' </summary>
    ''' <value>true-hide;false-display</value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property ShowList As Boolean()
        Get
            Return m_ShowList
        End Get
        Set(value As Boolean())
            m_ShowList = value
        End Set
    End Property

#End Region

#Region "StockInfoChart  option"
    Public Property DisplayProfit As Boolean
        Get
            Return m_DisplayProfit
        End Get
        Set(value As Boolean)
            m_DisplayProfit = value
        End Set
    End Property

#End Region

#Region "Alert option"

    Public Property Alert As clsAlert
        Get
            Return m_Alert
        End Get
        Set(ByVal value As clsAlert)
            m_Alert = value
        End Set
    End Property
#End Region

#End Region

#Region "method"


    Sub New()
        Dim i As Integer

        m_IsScroll = False
        m_DisplayProfit = False

        'default display all
        ReDim m_ShowList(clsStockInfo.FieldNumber)
        For i = 0 To clsStockInfo.FieldNumber
            m_ShowList(i) = False
        Next

        m_Alert = New clsAlert
      
    End Sub

#End Region

    Private m_IsScroll As Boolean 'if scroll the text
    Private m_ShowList() As Boolean 'hide fields list
    Private m_DisplayProfit As Boolean 'if display profit percentage in chart control
    Private m_Alert As clsAlert


End Class


Module modUIOption


    ''' <summary>
    ''' load UI option from default file
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function LoadUIOption() As clsUIOption
        Return LoadUIOption(UIOptionFilePath)
    End Function

    ''' <summary>
    ''' load UI option from file
    ''' </summary>
    ''' <param name="strPath"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function LoadUIOption(strPath As String) As clsUIOption
        Dim UIOptionTmp As New clsUIOption
        Dim stream As System.IO.FileStream
        Try
            If My.Computer.FileSystem.FileExists(strPath) Then
                'load UI Option from file
                Dim formatter As System.Runtime.Serialization.Formatters.Binary.BinaryFormatter = New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
                stream = New System.IO.FileStream(strPath, IO.FileMode.Open, IO.FileAccess.Read)

                UIOptionTmp = CType(formatter.Deserialize(stream), clsUIOption)
                stream.Close()
            End If
        Catch ex As Exception
            stream.Close()
        End Try
        Return UIOptionTmp
    End Function

    ''' <summary>
    ''' save UI option to default path
    ''' </summary>
    ''' <param name="UIOption"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function SaveUIOption(UIOption As clsUIOption) As Boolean
        Return SaveUIOption(UIOption, UIOptionFilePath)
    End Function

    ''' <summary>
    ''' save UI option to path
    ''' </summary>
    ''' <param name="UIOption"></param>
    ''' <param name="FilePath"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function SaveUIOption(UIOption As clsUIOption, FilePath As String) As Boolean
        'save options to file
        Try
            Dim formatter As System.Runtime.Serialization.Formatters.Binary.BinaryFormatter = New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
            Dim stream As System.IO.FileStream = New System.IO.FileStream(FilePath, IO.FileMode.Create, IO.FileAccess.Write)
            formatter.Serialize(stream, UIOption)
            stream.Flush()
            stream.Close()
        Catch ex As Exception
            Return False
        End Try

        Return True
    End Function
End Module